﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessObjects.BO_GetObjects;
using LibraryO2S;

public partial class Controls_ucListProducts : System.Web.UI.UserControl
{
    string category_id;

    public string Category_id
    {
        get { return category_id; }
        set { category_id = value; }
    }
    string page_size;

    public string Page_size
    {
        get { return page_size; }
        set { page_size = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadListProduct();
        }
    }

    protected void loadListProduct()
    {
        try
        {
            int size = Convert.ToInt32(page_size);
            int cur_page = Convert.ToInt32(Request["cur_page"]);
            if (cur_page == 0)
                cur_page = 1;
            string url = Request.Url.AbsoluteUri;
            if (url.IndexOf("&cur_page") > 0)
            {
                url = url.Remove(url.IndexOf("&cur_page"));
            }

            url += "&cur_page=$CUR_PAGE";
            DataTable objDT = BO_Products.SelectByCategory(Convert.ToInt32(cur_page), Convert.ToInt32(page_size), Convert.ToInt32(category_id));
            if (objDT.Rows.Count > 0)
            {
                pagerContainer.InnerHtml = O2S_Pager.Paging(size, cur_page, Convert.ToInt32(objDT.Rows[0]["row_count"]), url);
                rptListProduct.DataSource = objDT;
                rptListProduct.DataBind();
            }
        }
        catch (Exception)
        {

            throw;
        }
    }

    protected string getEvent(int index)
    {
        if (index % 2 == 0)
        {
            return "";
        }
        else
        {
            return "even";
        }
    }

    protected string getPrice(string unit_price)
    {
        decimal price = Convert.ToDecimal(unit_price);
        string strPrice = price.ToString();
        if (price > 1000000)
        {
            int dTemp = 0;
            dTemp += Convert.ToInt32(price / 1000000);
            strPrice = dTemp + " Triệu ";
            if (price - Convert.ToDecimal(dTemp * 1000000) > 0)
            {
                strPrice += (price - Convert.ToDecimal(dTemp * 1000000)) / 1000;
            }
        }
        return strPrice;
    }
}